package cn.rkylin.oms.goods.vo;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.rkylin.oms.goods.domain.PrjSku;

/**
 * 系统规格与项目关联值对象，用于满足前台展示、系统间交互的需要
 *
 * @author wangxing
 * @version 1.0.0
 * @created 2017-7-5
 */
public class PrjSkuVO extends PrjSku {
    /**
     * 序列化id
     */
    private static final long serialVersionUID = 1197683326993484879L;

    /**
     * 状态定义
     */
    private static final String OPERATION_BTN_ENABLE = "<button onclick=\"operationEnable(this)\" prjSkuId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;启用</button>";
    private static final String OPERATION_BTN_DELETE = "<button onclick=\"operationDelete(this)\" prjSkuId=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";
    private static final String CHECK_ITEM = "<input name=\"chkPrjSku\" prjSkuId=\"%s\" isGifts=\"%s\" goodsId=\"%s\" goodsCode=\"%s\" goodsName=\"%s\" skuId=\"%s\" skuCode=\"%s\" skuName=\"%s\" salePrice=\"%s\" goodsSkuCost=\"%s\" type=\"checkbox\" />";
    private static final String RADIO_ITEM = "<input name=\"chkPrjSku\" prjSkuId=\"%s\" isGifts=\"%s\" goodsId=\"%s\" goodsCode=\"%s\" goodsName=\"%s\" skuId=\"%s\" skuCode=\"%s\" skuName=\"%s\" salePrice=\"%s\" goodsSkuCost=\"%s\" type=\"radio\" />";

    private String goodsType;
    private String goodsSkuCount;
    private String discount;
    private String actualPrice;
    private String saleCash;
    private String actualCash;
    private String amount;
    private String useCount;
    private String shippingCount;
    private String note;
    private String chk;
    private String radio;

    // 标准进价
    private String stanPurcPrice;

    // 标准售价
    private String salePrice;

    /**
     * 成本价(商品选择列表)
     */
    private String costPrice;

    /**
     * 允许赠品(商品选择列表)
     */
    private String isGifts;

    /**
     * 虚拟商品(商品选择列表)
     */
    private String isVirt;

    /*
     * 规格条码(商品选择列表)
     */
    private String barCode;

    private List<String> listSkuId;

    /**
     * 成本价(用于新增补发单)
     */
    private BigDecimal goodsSkuCost;

    /**
     * 启用、删除按钮扩展
     */
    private String operation;

    /**
     * orderBy子句
     */
    private String orderBy;

    /**
     * 搜索条件
     */
    private String searchCondition;

    /**
     * 赠品标记（补发单）
     */
    private String isGift;

    public String getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(String goodsType) {
        this.goodsType = goodsType;
    }

    public String getGoodsSkuCount() {
        return goodsSkuCount;
    }

    public void setGoodsSkuCount(String goodsSkuCount) {
        this.goodsSkuCount = goodsSkuCount;
    }

    public String getDiscount() {
        return discount;
    }

    public void setDiscount(String discount) {
        this.discount = discount;
    }

    public String getActualPrice() {
        return actualPrice;
    }

    public void setActualPrice(String actualPrice) {
        this.actualPrice = actualPrice;
    }

    public String getSaleCash() {
        return saleCash;
    }

    public void setSaleCash(String saleCash) {
        this.saleCash = saleCash;
    }

    public String getActualCash() {
        return actualCash;
    }

    public void setActualCash(String actualCash) {
        this.actualCash = actualCash;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getUseCount() {
        return useCount;
    }

    public void setUseCount(String useCount) {
        this.useCount = useCount;
    }

    public String getShippingCount() {
        return shippingCount;
    }

    public void setShippingCount(String shippingCount) {
        this.shippingCount = shippingCount;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public List<String> getListSkuId() {
        return listSkuId;
    }

    public void setListSkuId(List<String> listSkuId) {
        this.listSkuId = listSkuId;
    }

    public String getOperation() {
        StringBuffer opButton = new StringBuffer();
        if (StringUtils.isNotEmpty(getPrjSkuId())) {
            opButton.append(String.format(OPERATION_BTN_ENABLE, getPrjSkuId()));
            opButton.append("&nbsp;");
            opButton.append(String.format(OPERATION_BTN_DELETE, getPrjSkuId()));
        }
        operation = opButton.toString();
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getOrderBy() {
        // 此字段需要防止sql注入
        return orderBy == null ? null : orderBy.replaceAll(".*([';]+|(--)+).*", " ");
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getSearchCondition() {
        return searchCondition;
    }

    public void setSearchCondition(String searchCondition) {
        this.searchCondition = searchCondition;
    }

    public String getStanPurcPrice() {
        return stanPurcPrice;
    }

    public void setStanPurcPrice(String stanPurcPrice) {
        this.stanPurcPrice = stanPurcPrice;
    }

    public String getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(String salePrice) {
        this.salePrice = salePrice;
    }

    public String getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(String costPrice) {
        this.costPrice = costPrice;
    }

    public String getIsGifts() {
        return isGifts;
    }

    public void setIsGifts(String isGifts) {
        this.isGifts = isGifts;
    }

    public String getIsVirt() {
        return isVirt;
    }

    public void setIsVirt(String isVirt) {
        this.isVirt = isVirt;
    }

    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public String getIsGift() {
        return isGift;
    }

    public void setIsGift(String isGift) {
        this.isGift = isGift;
    }

    public String getChk() {
        String type = "";
        if ("y".equals(this.getIsGift())) {
            // 添加赠品
            type = "赠";
        } else {
            // 添加商品
            if ("y".equals(this.getIsVirt())) {
                type = "虚";
            } else {
                type = "销";
            }
        }
        return String.format(CHECK_ITEM, this.getPrjId(), type, this.getGoodsId(), this.getGoodsCode(), this.getGoodsName(), this.getSkuId(),
                this.getSkuCode(), this.getSkuName(), this.getSalePrice(),this.getGoodsSkuCost()).toString();
    }
    public String getRadio() {
        String type = "";
        if ("y".equals(this.getIsGift())) {
            // 添加赠品
            type = "赠";
        } else {
            // 添加商品
            if ("y".equals(this.getIsVirt())) {
                type = "虚";
            } else {
                type = "销";
            }
        }
        return String.format(RADIO_ITEM, this.getPrjId(), type, this.getGoodsId(), this.getGoodsCode(), this.getGoodsName(), this.getSkuId(),
                this.getSkuCode(), this.getSkuName(), this.getSalePrice(),this.getCostPrice()).toString();
    }

    public void setChk(String chk) {
        this.chk = chk;
    }
    public void setRadio(String radio) {
        this.radio = radio;
    }

    public BigDecimal getGoodsSkuCost() {
        return goodsSkuCost;
    }

    public void setGoodsSkuCost(BigDecimal goodsSkuCost) {
        this.goodsSkuCost = goodsSkuCost;
    }

}
